Skip to content

[FIX] document_page_reference: avoid duplicate reference on copy and enforce uniqueness - #634

Open
miquelrosell99 wants to merge 2 commits into
OCA:18.0from
miquelrosell99:18.0-fix-document-page-reference-unique
Open

miquelrosell99 wants to merge 2 commits into
OCA:18.0from
miquelrosell99:18.0-fix-document-page-reference-unique

Conversation

@miquelrosell99

Copy link
Copy Markdown

Before this fix:

  • Duplicating a document.page copied the reference value as-is, so the new page ended up with the same reference as the original.
  • The module only had a Python uniqueness check; there was no database-level unique constraint.

This fix:

  • Sets copy=False on the reference field so copies get a fresh reference generated from the copied page name.
  • Adds a SQL unique constraint on reference.
  • Includes a pre-migration script that clears duplicate references (keeping the oldest record) so the constraint can be applied on databases that already have duplicates.
  • Adds a regression test.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @etobella,
some modules you are maintaining are being modified, check this out!

@OCA-git-bot OCA-git-bot added series:18.0 mod:document_page_reference Module document_page_reference labels Jul 31, 2026
@miquelrosell99
miquelrosell99 force-pushed the 18.0-fix-document-page-reference-unique branch from 661556f to 3d6e0d8 Compare November 2, 2026 07:26
@oca-cla-bot

oca-cla-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@etobella

etobella commented Nov 2, 2026

Copy link
Copy Markdown
Member

@miquelrosell99 can you sign the CLA?

@miquelrosell99

Copy link
Copy Markdown
Author

Done — I've just signed the OCA Individual CLA. Thanks for the reminder, @etobella!

The new UNIQUE(reference) SQL constraint fires on the INSERT/UPDATE
itself, before the Python @api.constrains check, so duplicate references
now raise psycopg2 IntegrityError instead of ValidationError. Update the
two pre-existing tests to expect IntegrityError (with mute_logger and the
per-test savepoint that TransactionCase provides), following the same
pattern as Odoo core tests for SQL constraints.
@miquelrosell99

Copy link
Copy Markdown
Author

Hi @etobella — the CI issue is fixed (the new SQL constraint fires before the Python check, so the two pre-existing tests now expect IntegrityError, matching core's SQL-constraint test pattern). All checks are green. Could you re-review when you have a moment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:document_page_reference Module document_page_reference series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants